<template>
	<view>
		<view>
			<u-toast ref="uToast" />
		</view>
		<u-modal v-model="show2" :content="content">
			<u-form :model="toReport" ref="uForm">
				<u-form-item label="举报原因">
					<u-input v-model="toReport.reportReasonsDescribe" />
				</u-form-item>
			</u-form>
			<u-button @click="zeroAddToReport()">提交</u-button>
		</u-modal>

		<!-- 轮播图 -->
		<view>
			<u-swiper height="600" :list="lunbotu"></u-swiper>
		</view>
		<!-- 主体 -->
		<view class="">
			<view class="goods-title">
				<view class="goods-item-price-box">
					<view class="goods-item-price">
						<view class="price-number-box">
							<view class="price-number">
								<text>￥</text>
								<text class="yuan">{{list.orderDetailPrice}}</text>
							</view>
						</view>
						<view class="original-price gray">
							价格
							<text class="line-through">￥9999</text>
						</view>
					</view>
				</view>
				<view class="goods-name">
					<view class="box" style="font-size: 24px;">
						{{list.orderDetailName}}
					</view>
				</view>
				<view class="sale-info-box">
					<view class="sale-info">
						<view>库存：{{list.orderDetailRepertory}}</view>
						<view>销量：{{list.orderDetailSales}}</view>
					</view>
				</view>
				<view class="freight-box">
					<view class="title">
						运费
					</view>
					<view class="center">
						在线支付免运费
					</view>
				</view>
				<view class="guarantee">
					<view class="guarantee-item">
						<u-icon name="checkmark-circle"></u-icon>
						<text class="text">可配送海外</text>
					</view>
					<view class="guarantee-item">
						<u-icon name="checkmark-circle"></u-icon>
						<text class="text">店铺发货&售后</text>
					</view>
					<view class="guarantee-item">
						<u-icon name="checkmark-circle"></u-icon>
						<text class="text">7天无理由退货</text>
					</view>
					<view class="guarantee-item">
						<u-icon name="checkmark-circle"></u-icon>
						<text class="text">闪电退款</text>
					</view>
					<view class="guarantee-item">
						<u-icon name="checkmark-circle"></u-icon>
						<text class="text">极速审核</text>
					</view>
					<view class="guarantee-item">
						<u-icon name="checkmark-circle"></u-icon>
						<text class="text">极速发货</text>
					</view>

					<!-- 认领规则 -->
					<view class="guarantee-item" v-if="goodsinfo.goodsType === 1">
						<u-icon name="checkmark-circle"></u-icon>
						<text class="text">保证成熟立即发货</text>
					</view>
					<view class="guarantee-item">
						<u-icon name="checkmark-circle"></u-icon>
						<text class="text">保证质量</text>
					</view>
					<view class="guarantee-item">
						<u-icon name="checkmark-circle"></u-icon>
						<text class="text">认领金秒退款</text>
					</view>
					<!-- <view class="guarantee-item">
						<u-icon name="checkmark-circle"></u-icon>
						<text class="text">举报商品违规</text>
					</view> -->

					<view class="guarantee-item" @click="zeroAddToReportOpen()">
						<u-icon name="checkmark-circle"></u-icon>
						<text class="text">举报商品违规</text>
					</view>
				</view>
			</view>

			<view class="comment-box">
				<view class="freight-box">
					<view class="title">
						评价
					</view>
					<view class="center">

					</view>
					<view class="more" @click="gotoCommentList">
						<u-icon name="more-dot-fill" size="36"></u-icon>
					</view>
				</view>
				<view>
					<!-- <goods-comment :commentList="commentList" /> -->
					<view class="comment-btn">
						<u-button shape="circle" size="medium" class="all-btn" @click="gotoCommentList">查看全部评价
						</u-button>
					</view>
				</view>
			</view>
		</view>

		<!-- 弹出层 -->
		<u-popup v-model="skuIsShow" mode="bottom" border-radius="30" :closeable="true" height="350px">
			<view class="goods-info">
				<view class="goods-list">
					<!-- <image :src="list[0].pic" mode="aspectFill" class="image-width-168 goods-image"></image> -->
					<view class="goods-content">
						<view class="goodmoney">￥{{list.spellGroupPrice}}</view>
						<view class="kuncun">
							<text>库存 {{list.orderDetailRepertory}} 件</text>
						</view>
						<view>
							请选择
						</view>
					</view>
				</view>
				<view class="goods-list">
					<text>选择拼团人数</text>
					<view class="number-box1">
						<u-number-box v-model="claimNum" :min="1" :max="3"></u-number-box>
					</view>
				</view>

				<view>
					<button class="quebut" @click="tochoose">确认</button>
				</view>
			</view>

		</u-popup>
		<!-- 加入购物车弹出框 -->
		<u-popup v-model="goumaishow" mode="bottom" border-radius="30" :closeable="true" height="350px">
			<view class="goods-info">
				<view class="goods-list">
					<image :src="list.fileList[0].pictureUrl" mode="aspectFill" class="image-width-168 goods-image">
					</image>
					<view class="goods-content">
						<view class="goodmoney">￥{{list.orderDetailPrice}}</view>
						<view class="kuncun">
							<text>库存 {{list.orderDetailRepertory}} 件</text>
						</view>
						<view>
							请选择
						</view>
					</view>
				</view>

				<view class="goods-list">
					<text>数量</text>
					<view class="number-box">
						<u-number-box v-model="list.concat" :min="1" :max="999"></u-number-box>
					</view>
				</view>
				<view>
					<button @click="TowAddShop(list.fileList[0].pictureUrl)" class="quebut">确认</button>
				</view>
			</view>

		</u-popup>
		<u-popup v-model="showGoodsSkuThree1" mode="bottom" border-radius="30" :closeable="true" height="350px">
			<view class="goods-info">
				<view class="goods-list">
					<image :src="list.fileList[0].pictureUrl" mode="aspectFill" class="image-width-168 goods-image">
					</image>
					<view class="goods-content">
						<view class="goodmoney">￥{{list.orderDetailPrice}}</view>
						<view class="kuncun">
							<text>库存 {{list.orderDetailRepertory}} 件</text>
						</view>
						<view>
							请选择
						</view>
					</view>
				</view>

				<view class="goods-list">
					<text>数量</text>
					<view class="number-box">
						<u-number-box v-model="value" @change="valChange" :min="1" :max="kucun"></u-number-box>
					</view>
				</view>
				<view>
					<button @click="submit(list)" class="quebut">确认</button>
				</view>
			</view>

		</u-popup>
		<!-- 确认弹框 -->
		<view>
			<u-modal v-model="show" :content-style="{margin:'20px'}" @confirm="tosuccess">
				<template>
					确认与 <text style="color: red;">{{claimNum}}</text> 人进行拼团，缴纳 <text style="color: red;">10%</text>
					认领金，并分享到芸圈？
				</template>
			</u-modal>
		</view>

		<!-- 底部栏 -->
		<view class="navigation">
			<view class="left">
				<u-grid :col="3">
					<u-grid-item :customStyle="customStyle" @click="gotoNavigation('kefu')">
						<u-icon name="server-fill" :size="40"></u-icon>
						<view class="grid-text">客服</view>
					</u-grid-item>
					<u-grid-item :customStyle="customStyle" @click="gotoNavigation('home')">
						<u-icon name="home" :size="40"></u-icon>
						<view class="grid-text">店铺</view>
					</u-grid-item>
					<u-grid-item :customStyle="customStyle" @click="gotoNavigation('cart')">
						<!-- 	<u-badge count="9" :offset="[0, 10]"></u-badge> -->
						<u-icon name="shopping-cart" :size="40"></u-icon>
						<view class="grid-text">购物车</view>
					</u-grid-item>
				</u-grid>
			</view>
			<view class="right">
				<view class="cart btn u-line-1" @click="showGoodsSku" v-if="list.orderDetailStatus==0">拼团认领</view>
				<view class="buy btn u-line-1" @click="showGoodsSku" v-if="list.orderDetailStatus==0">立即认领</view>
				<view class="cart btn u-line-1" @click="goumaishow=true">添加购物车</view>
				<view class="buy btn u-line-1" @click="showGoodsSkuThree" v-if="list.orderDetailStatus==1">立即购买</view>
			</view>
		</view>
	</view>

	</view>
</template>

<script>
	import request from '../../../utils/request.js'
	import uniNumberBox from '../../../node_modules/uview-ui/components/u-number-box/u-number-box.vue'
	export default {
		components: {

		},
		data() {
			return {
				toReport: {
					beforeUserId: undefined,
					reportReasonsDescribe: undefined,
					reportReasons: undefined,
					orderDetailId: undefined
				},
				show2: false,
				content: '填写举报信息',

				current: 0, // 轮播图index
				orderDetailId: undefined,
				show: false,
				claimNum: 1,
				goodsId: '',
				list: [],
				customStyle: {
					'padding': '16rpx 0'
				},
				goodsinfo: {},
				skuIsShow: false,
				goumaishow: false,
				showGoodsSkuThree1: false,
				commentList: [], //评论集合
				userid: undefined,
				value: undefined,
				lunbotu: [],
				value: undefined,
				kucun: undefined,
				goumaishow: false,
				value: 0,
				userid: undefined,
				lunbotu: [],
				zongjia: 0,
				lunbotu: [],
				shopList: {
					beforeUserId: '',
					shangpinid: '',
					orderDetailPrice: '',
					orderDetailName: '',
					flag: '',
					concat: '',
					pictureUrl: ''
				}
			}
		},
		onLoad(options) {
			uni.getStorage({
				key: 'beforeUser',
				success: (res) => {
					this.shopList.beforeUserId = res.data.beforeUserId
				}
			})
			this.shangpinid = options.shangpinid;
			/* 商品信息 */
			// this.getlunboList(options.goodsId);
			this.getlunbotu()
		},
		methods: {
			submit(list) {
				console.log(this.list)
				uni.navigateTo({
					url: '../../order/create/payxiang?to=' + this.zongjia + '&DETAIL=' + this.shangpinid +
						'&value=' + this.value
				})
			},
			valChange(e) {
				this.value = e.value
				this.zongjia = this.list.orderDetailPrice * e.value
				console.log(this.zongjia)
			},
			zeroAddToReportOpen() {
				// beforeUserId:undefined,
				// reportReasonsDescribe:undefined,
				// reportReasons:undefined,
				// orderDetailId:undefined

				this.toReport = {}
				this.toReport.beforeUserId = this.userid
				this.toReport.orderDetailId = this.shangpinid
				console.log(this.toReport)
				this.show2 = true;
			},
			zeroAddToReport() {
				this.show2 = false,
					uni.request({
						url: 'http://localhost:8002/detail/bgs/to-report/zeroAddToReport',
						method: "POST",
						dataType: "JSON",
						data: this.toReport,
						success: (res) => {
							uni.showToast({
								title: "举报成功",
								icon: "none"
							})
						}
					})
			},
			// 添加购物车
			TowAddShop(a) {
				this.shopList.shangpinid = this.shangpinid
				console.log(this.shopList.shangpinid)
				this.shopList.orderDetailPrice = this.list.orderDetailPrice
				this.shopList.orderDetailName = this.list.orderDetailName
				this.shopList.flag = true
				this.shopList.concat = this.list.concat
				this.shopList.pictureUrl = a
				console.log(this.shopList)
				uni.request({
					url: 'http://localhost:9090/before/bgs/circle/TowAddShop',
					method: 'POST',
					data: {
						shopList: this.shopList
					},
					success: (res) => {
						this.goumaishow = false
						this.$refs.uToast.show({
							title: '添加成功',
							type: 'success'
						})
					}
				});
			},
			// 监听轮播图切换
			handleDotChange(e) {
				this.current = e.detail.current;
			},
			/* 确认按钮 */
			tochoose() {
				this.show = true

			},
			/* 确认认领 */
			tosuccess() {
				console.log(111);
				var item = {
					goodsId: this.goodsId,
					isGroup: 1,
					claimNum: this.claimNum,
					goodsMoney: this.goodsinfo.goodsMoney
				}
				uni.navigateTo({
					url: '../pay-ren/pay-ren?item=' + encodeURIComponent(JSON.stringify(item))
				})
			},
			getlunboList(goodsId) {
				request({
					url: '/goods/goods/getlunboList',
					data: {
						goodsId: goodsId
					},
					success: (res) => {
						console.log(res.data);
						this.list = res.data.data.data.goodsPic
						this.goodsinfo = res.data.data.data
					}
				})
			},
			/* 打开认领弹框 */
			showGoodsSku() {
				this.skuIsShow = true
			},
			/* 打开购买弹框 */
			showGoodsSku1() {
				this.goumaishow = true
			},

			showGoodsSkuThree() {
				this.showGoodsSkuThree1 = true
			},
			/* 获取商品轮播图 */
			getlunbotu() {
				request({
					url: '/detail/bgs/order-detail/fourOpenShop?shangpinid=' + this
						.shangpinid,
					method: 'Get',
					success: (res) => {
						console.log(res.data.data.data)
						this.list = res.data.data.data[0]
						var aa = res.data.data.data[0].orderDetailRepertory
						this.kucun = Number(aa)
						//this.storeId = res.data.data.data[0].storeId
						this.orderDetailId = res.data.data.data[0].orderDetailId
						for (var i = 0; i < res.data.data.data[0].fileList.length; i++) {
							let lun = {
								image: res.data.data.data[0].fileList[i].pictureUrl
							}
							this.lunbotu.push(lun)
						}
						this.ThreeFrontInsert()
					}
				})
			},
			ThreeFrontInsert(orderDetailId) {
				console.log(this.orderDetailId)
				uni.getStorage({
					key: 'beforeUser',
					success: (res) => {
						this.userid = res.data.beforeUserId
					},
				})
				request({
					url: '/before/bgs/track/ThreeTrackRedis',
					data: {
						beforeUserId: this.userid,
						orderDetailId: this.orderDetailId
					},
					method: 'Get',
					success: (res) => {
						console.log("更新足迹成功")
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.quebut {
		background-color: red;
		margin-top: 50px;
		border-radius: 30px;
		width: 90%;
		color: #FFFFFF;
	}

	.number-box {
		margin-left: 60%;
	}

	.number-box1 {
		margin-left: 43%;
	}

	.goods-list {
		display: flex;
		flex-direction: row;
		margin: 20px;
	}

	.goods-list image {
		width: 100px;
		height: 100px;
	}

	.goods-content {
		flex: 1;
		line-height: 30px;
		margin-left: 20px;
	}

	.goodmoney {
		color: red;
		font-size: 18px;
		font-weight: bold;
	}

	.goods-title {
		background: #fff;
		padding-top: 15px;
		border-bottom-left-radius: 12px;
		border-bottom-right-radius: 12px;
	}

	.goods-item-price-box {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 0 15px;

		.goods-item-price {


			.price-number-box {
				line-height: 22px;
				display: flex;


				.yuan {
					font-size: 60rpx;
				}

				.price-number {
					font-size: 18px;
					font-weight: 700;
					color: #ff201f;
					margin-right: 20rpx;
				}

				.u-size-mini {
					padding: 12rpx 18rpx;
					transform: scale(0.8);
					font-size: 12px;
				}
			}

			.original-price {
				font-size: 13px;
				line-height: 13px;
				padding: 5px 0;
				box-sizing: border-box;
				color: #999;

				.line-through {
					text-decoration: line-through;
				}
			}
		}

		.collection {
			color: #333;
			height: 22px;
			font-size: 12px;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
		}

		.original-price {
			font-size: 13px;
			line-height: 13px;
			padding: 5px 15px;
			box-sizing: border-box;
		}
	}

	.goods-name {
		position: relative;

		.box {
			font-size: 16px;
			font-weight: 500;
			position: relative;
			padding: 0 75px 0 15px;
			box-sizing: border-box;
			color: #000;
			padding-top: 20rpx;
		}

		.share-btn {
			color: #999;
			border-radius: 25px 0 0 25px;
			background-color: #ededed;
			position: absolute;
			right: 0;
			top: 15px;
			padding: 12rpx 16rpx;
			font-size: 28rpx;
			line-height: 28rpx;

			.text {
				margin-left: 10rpx;
			}
		}
	}

	.sale-info-box {
		color: #999;
		padding: 0 30rpx 30rpx 30rpx;
		font-size: 12px;

		.sale-info-tip {
			padding: 14px 0;
			line-height: 16px;
		}

		.sale-info {
			display: flex;
			justify-content: space-between;
			padding-top: 14rpx;

		}
	}

	.discount-box {
		margin-top: 24rpx;
		background-color: #FFF;
		border-radius: 24rpx;
	}

	.coupon-box,
	.promote-sales-box,
	.specs-option-box,
	.logistics-box,
	.freight-box {
		display: flex;
		width: 100%;
		align-items: center;
		font-size: 28rpx;
		line-height: 28rpx;
		padding: 24rpx 30rpx 24rpx 30rpx;
		box-sizing: border-box;
	}

	.coupon-box .title,
	.promote-sales-box .title,
	.specs-option-box .title,
	.logistics-box .title,
	.freight-box .title {
		width: 100rpx;
		font-weight: 700;
	}

	.coupon-box .more,
	.specs-option-box .more,
	.logistics-box .more,
	.freight-box .more {
		margin-left: auto;
	}

	.coupon-box {
		.center {
			line-height: 60rpx;

			.coupon-tag {
				background-color: #fa3534;
				margin-right: 10rpx;

				/* #ifdef MP */
				border-radius: 100rpx;

				.u-tag {
					background-color: #fa3534;
					padding: 12rpx;
				}

				/* #endif */
			}
		}
	}

	.promote-sales-box {
		position: relative;

		.center {
			width: 80%;

			.promotion-box {
				display: flex;
				align-items: center;
				padding: 5px 0;

				.promotion-text {
					width: 70%;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
					margin-left: 20rpx;
				}
			}
		}

		.more {
			position: absolute;
			right: 15px;
			top: 15px;
		}
	}

	.base-box {
		margin-top: 24rpx;
		background-color: #FFF;
		border-radius: 24rpx;
	}

	.logistics-box .center {
		width: 76%;

		.addr-item {
			padding: 10rpx;
			line-height: 36rpx;
		}
	}

	.guarantee {
		display: flex;
		flex-wrap: wrap;
		padding: 10px 15px 15px 15px;
		font-size: 12px;

		.guarantee-item {
			color: #999;
			padding-right: 15px;
			padding-top: 5px;

			.text {
				padding-left: 2px;
			}
		}
	}


	.navigation {
		display: flex;
		border-top: solid 2rpx #f2f2f2;
		border-bottom: solid 2rpx #f2f2f2;
		background-color: #ffffff;
		width: 100%;
		position: fixed;
		bottom: 0;
		z-index: 999;

		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);

		.left {
			width: 50%;
		}

		.right {
			display: flex;
			font-size: 28rpx;
			align-items: center;
			justify-content: center;
			border-bottom: solid 2rpx #f2f2f2;

			.btn {
				line-height: 66rpx;
				padding: 0 30rpx;
				border-radius: 36rpx;
				color: #ffffff;
			}

			.cart {
				background-color: #ed3f14;
				margin-right: 10rpx;
			}

			.buy {
				background-color: #ff7900;
			}
		}
	}

	.comment-box {
		margin-top: 24rpx;
		background-color: #FFF;
		border-radius: 24rpx;
	}

	.goods-content-box {
		.u-image {
			vertical-align: middle;
			font-size: 0;
		}
	}

	.comment-btn {
		padding: 20rpx 50rpx;
		text-align: center;

		.all-btn {
			margin: auto;
		}
	}
</style>
